home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
033a
/
mxtms_10.zip
/
MAXTIME.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-27
|
12KB
|
351 lines
/****************************************************************************/
/* */
/* Maxtime.c Version 1.0 By Craig Derouen */
/* A Maximus CBBCS Timebank program */
/* */
/* */
/****************************************************************************/
#define MAXTIME_MAIN
#include "maxtime.h"
#include "globals.h"
int secret = FALSE;
void main(int argc,char **argv)
{
int x;
int mtime,mbank;
unsigned y;
int tport=-1;
struct find_t fileinfo;
time_t thistime;
exitcode = 0;
Task = 0;
MinutesWanted = 0;
mtime = 0;
mbank = 0;
SysopMode = FALSE;
UserBBS[0] = 0;
strcpy(MCfgFile,"Maxtime.cfg");
strcpy(LastUse,"Lastuser.bbs");
for (x = 1; x < argc; x++) { /* Parse out command line */
if (argv[x][0] == '-' || argv[x][0] == '/') {
y = toupper(argv[x][1]); /* Argument switch */
switch (y) {
case '?': /* Show switches only */
show_opts();
break;
case 'L':
IsLocal = TRUE;
break;
case 'P': /* Specify port */
tport = argv[x][2] - '1';
break;
case 'S': /* Sysop mode */
SysopMode = TRUE;
IsLocal = TRUE;
break;
case 'T':
Task = argv[x][2] - '0';
sprintf(LastUse,"Lastus%02d.bbs",Task);
break;
case 'M':
y = toupper(argv[x][2]); /* Argument switch */
if (y == 'T')
mtime = atoi(argv[x]+3);
else if (y == 'B') mbank = atoi(argv[x]+3);
break;
case 'Z': /* Show parms */
secret = TRUE;
show_opts();
break;
}
}
else { /* Only non-switch argument specifies the MaxTime config file */
strcpy(MCfgFile,argv[x]);
}
}
if (!SysopMode) {
/* Load in the Restart file data */
sprintf(temp,"Restar%02d.bbs",Task);
y = FALSE;
if(stat(temp,&fbuf) == 0 ) {
Rstart = (struct _restart *) malloc(sizeof(struct _restart));
if (Rstart != NULL) {
x = sopen(temp,O_BINARY | O_RDWR,SH_DENYNO,S_IREAD);
if (x != -1) {
if(read(x,(char *)Rstart,sizeof(struct _restart)) == 0)
y = TRUE;
close(x);
if (tport < 0)
com_port = Rstart->port;
else com_port = tport;
}
else y = TRUE;
}
else y = TRUE;
}
else y = TRUE;
if(y) {
strout("Error reading Restart file, notify sysop!");
exit(1);
}
if (com_port < 0 || com_port == 0x00ff)
IsLocal = TRUE;
if (!IsLocal) {
if(!FossilInit())
aborterror(FILEOPEN,"Couldn't open FOSSIL");
}
/* Compute how much time has the user been on already */
init(); /* Start up things, read cfg file */
if (mtime > 0)
MaxTimeSession = (unsigned) mtime;
if (mbank > 0)
MaxBankSession = (unsigned) mbank;
/* Read in the lastuser.bbs file */
x = sopen(LastUse,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD);
if (x == -1)
aborterror(FILEOPEN,"Missing Lastuse file");
y = read(x,&LastUser,sizeof(struct _usr));
user_slen = (LastUser.struct_len ? LastUser.struct_len * 20 : 180);
lseek(x,0L,SEEK_SET);
y = read(x,&LastUser,user_slen);
if (y < (unsigned) user_slen) { /* Humm couldnt read all of file! */
close(x);
aborterror(FILEOPEN,"Error reading LastUse file");
}
close(x); /* We only need the file for the structure info */
/* Compute BBStime which is amount of time already spent on bbs */
if( (x = (int) ((Rstart->timeoff - Rstart->timeon) / 60L) - LastUser.timeremaining) < 0)
x = 0;
BBStime = (unsigned int) x;
UserCfgnum = 0; /* Startup */
newuser = FALSE;
if(stat(CfgFile,&fbuf) == 0 ) /* Does file exist? */
x = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
else x = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IWRITE);
if (x == -1)
aborterror(FILEOPEN,"Error opening/creating User config file");
UserCfgnum = find_config(x,LastUser.name,&USERCFG);
if (UserCfgnum < 0) { /* Couldn't be found */
newuser = TRUE;
memset(&USERCFG,0,sizeof(struct user_cfg));
memcpy(USERCFG.name,LastUser.name,36);
UserCfgnum = find_blconfig(x); /* Look for an empty slot */
if (UserCfgnum < 0) /* Couldn't be found */
UserCfgnum = new_user(x);
}
close(x); /* We only need the file for the structure info */
signon();
/* Check and see is user has already been on here once today. */
time(&thistime);
if ((thistime - USERCFG.lasttime) < (time_t)(86400)) { /* within 24 hours? */
IsToday = TRUE;
}
else {
IsToday = FALSE;
USERCFG.dailydep = 0;
USERCFG.dailywtd = 0;
}
menu();
}
else { /* Special Sysop mode to do packing, maintainence */
init(); /* Start up things, read cfg file */
sprintf(temp,"Begin, v%2.2f",Version);
logit(temp,'+');
strcpy(temp1,"Local sysop maintainence mode");
logit(temp1,':');
strout("MaxTime - a MAXIMUS timebank utility by Craig Derouen\r\n");
sprintf(temp,"\t *** Version %.2f ***\r\n",Version);
strout(temp);
strout(temp1);
strout("\n");
/* We still have to read the lastuse file, but just to get length for
later. So just look for ANY lastuser file. */
if(_dos_findfirst("Lastus??.bbs",_A_NORMAL,&fileinfo) == 0) {
strcpy(LastUse,fileinfo.name);
x = sopen(LastUse,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD);
if (x == -1)
aborterror(FILEOPEN,"Missing Lastuse file");
read(x,&LastUser,sizeof(struct _usr));
user_slen = (LastUser.struct_len ? LastUser.struct_len * 20 : 180);
close(x);
}
else aborterror(FILEOPEN,"Missing Lastuse file");
strcpy(LastUser.name,"Sysop"); /* Special mode */
Sys_menu();
}
deinit(0);
}
void menu(void)
{
char resp;
int choice;
int good,x;
choice = TRUE;
while (choice) {
setcolor(TextAttr[STD_TEXT]);
sprintf(temp,"\r\nYou have %lu minutes in the timebank currently.\r\n",USERCFG.banktime);
strout(temp);
strout("--------------------------------------------------------\r\n");
setcolor(TextAttr[MENU_KEY]);
strout("[A]dd time to your reserve [W]ithdraw time to use today\r\n");
strout("[V]ersion [Q]uit back to Maximus\r\n");
strout("[S]tatistics\r\n");
if (LastUser.priv >= ASSTSYSOP) {
setcolor(TextAttr[STD_TEXT]);
strout("[U]ser stats (Sysop function)\r\n");
}
strout("\r\n");
good = FALSE;
while (!good) {
timeremain();
setcolor(TextAttr[PROMPT_TEXT]);
strout("Choice --> ");
x = chrin();
resp = (char) toupper(x);
if(resp == '\r')
resp = '!';
good = TRUE;
chrout(resp);
strout("\r\n");
setcolor(TextAttr[STD_TEXT]);
switch (resp) {
case 'A': /* Add time to bank */
if(addtime())
choice = FALSE;
break;
case 'Q':
case 'G':
choice = FALSE;
break;
case 'S': /* User statistics */
setcolor(TextAttr[HILITE_TEXT]);
if (USERCFG.calls) {
if (IsToday)
sprintf(temp,"\r\nYou have run MaxTime %d times, including at least once today.\r\n",USERCFG.calls);
else sprintf(temp,"\r\nYou have run MaxTime %d times.\r\n",USERCFG.calls);
}
else sprintf(temp,"\r\nThis is your first run of MaxTime.\r\n");
strout(temp);
if (USERCFG.deposits) {
sprintf(temp,"You have made %u deposits and %u withdrawals in MaxTime.\r\n",USERCFG.deposits,USERCFG.withdraws);
strout(temp);
}
sprintf(temp,"You have been on the bbs for %u minutes.\r\n",BBStime);
strout(temp);
sprintf(temp,"You have been in MaxTime for %u minutes.\r\n",timeon());
strout(temp);
sprintf(temp,"You have %u minutes remaining on bbs.\r\n",LastUser.timeremaining - timeon());
strout(temp);
break;
case 'U':
if (LastUser.priv >= ASSTSYSOP)
Sys_menu();
break;
case 'V':
ShowVers();
break;
case 'W': /* Withdraw time from bank */
if(withdrawtime())
choice = FALSE;
break;
case '!': /* Redraw the full menu */
good = TRUE;
break;
default:
good = FALSE;
break;
}
}
}
}
/* Display version and compiler time to user. Put this function here
in this module since TIMESTAMP checks only this module for date */
void ShowVers(void)
{
struct tm *newtime;
time_t aclock;
setcolor(TextAttr[STD_TEXT]);
sprintf(temp,"MaxTime, Version %.2f, By Craig Derouen\r\n",Version);
strout(temp);
setcolor(TextAttr[ATTN_TEXT]);
sprintf(temp,"Running under DOS %d.%d\r\n",_osmajor,_osminor);
strout(temp);
setcolor(TextAttr[HILITE_TEXT]);
sprintf(temp,"Program was last compiled: %s\r\n",__TIMESTAMP__);
strout(temp);
setcolor(TextAttr[MENU_KEY]);
sprintf(temp,"Remaining heap: %u bytes\r\n",_memavl());
strout(temp);
time(&aclock);
newtime = localtime(&aclock);
setcolor(TextAttr[STD_TEXT]);
sprintf(temp,"Current date and time are: %s\r\n",asctime(newtime));
strout(temp);
}
void show_opts(void)
{
printf("\nMaxTime Version: %2.2f by Craig Derouen\n",Version);
printf("Last compiled: %s\n",__TIMESTAMP__);
if (secret) {
printf("\t\a\aWaka! Waka! Waka! Author's secret function!\n");
printf("\tRemaining heap: %u bytes\n",_memavl());
printf("Since you are NOT the author, I am aborting...\n\n");
}
printf("Command line options:\n");
printf("\t /P: Specify com port (1=Com1,2=Com2,etc) Usually not needed\n");
printf("\t /S: Local Sysop maintainence mode\n");
printf("\t /T: Specify Task number. Tells Maxmail we are running multiuser\n");
printf("\t /MT: Specify maximum time user may borrow from bank\n");
printf("\t /MB: Specify maximum time user deposit in bank\n");
printf("\t {Filename} use this file as alt MaxTime.cfg file\n");
exit(0);
}